package com.atguigu.yygh.user.controller;

import com.atguigu.yygh.common.R;
import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.user.service.UserService;
import com.atguigu.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author zhmwi
 * @Date 2021/7/20
 * @Dersciption
 */
@Api("用户管理接口")
@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private UserService userService;

    //后台 --查询用户列表
    @ApiOperation("带条件带分页查询用户列表")
    @GetMapping("{page}/{limit}")
    public R getUserListByConditionAndPage(@PathVariable Long page,
                                           @PathVariable Long limit,
                                           UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> pageParam = new Page<>(page, limit);
        IPage<UserInfo> pageModel = userService.selectPage(pageParam,userInfoQueryVo);
        return R.ok().data("pageModel",pageModel);
    }

    //后台 -- 锁定解锁用户
    @ApiOperation("锁定")
    @GetMapping("lock/{userId}/{status}")
    public R lock(@PathVariable("userId") Long userId,
                  @PathVariable("status") Integer status){
        userService.lock(userId,status);
        return R.ok();
    }
}
